package com.baseDemo.web.entity;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;

/**
 * 附件目录类
 * 
 * @author xianwei
 * 
 */
@Entity
@Table(name = "t_CatalogEntity")
@JsonIgnoreProperties(ignoreUnknown = true)
public class CatalogEntity implements Serializable {

	private static final long serialVersionUID = 5893393892480973394L;

	private String id;
	private String text;
	private String userId;

	private String icon;
	@Column(name="leaf")
	@Type(type="yes_no")
	private boolean leaf;
	private String parentId;
	private CatalogEntity parent;
	private Set<CatalogEntity> children;
	private Set<DocInfoEntity> docInfoEntities;

	@Id
	@GeneratedValue(generator = "system-uuid")
	@GenericGenerator(name = "system-uuid", strategy = "org.hibernate.id.UUIDGenerator")
	@Column(length = 50)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(length = 50)
	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	@Column(length = 50)
	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	@Column(length = 50)
	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE,
			CascadeType.REFRESH }, fetch = FetchType.EAGER)
	@JoinColumn(name = "parent")
	// 转化为json字符串时 过滤此字段
	@JsonIgnore
	public CatalogEntity getParent() {
		return parent;
	}

	public void setParent(CatalogEntity parent) {
		this.parent = parent;
	}

	@OneToMany(mappedBy = "parent")
	@JsonIgnore
	public Set<CatalogEntity> getChildren() {
		return children;
	}

	public void setChildren(Set<CatalogEntity> children) {
		this.children = children;
	}

	@OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, targetEntity=DocInfoEntity.class )
	@JoinColumn(name="catalogId") 
	@JsonIgnore
	public Set<DocInfoEntity> getDocInfoEntities() {
		return docInfoEntities;
	}

	public void setDocInfoEntities(Set<DocInfoEntity> docInfoEntities) {
		this.docInfoEntities = docInfoEntities;
	}

	public boolean isLeaf() {
		return leaf;
	}

	public void setLeaf(boolean leaf) {
		this.leaf = leaf;
	}
	@Transient
	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

}
